package Ldzy.Servlerts.com;

import Ldzy.Tabel.com.GoodsHockTable;
import Ldzy.bean.com.Goods;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;

public class GetAllGoodsesSServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        Collection<Goods> goods=GoodsHockTable.getAllgoodse();
//        JSONObject object=new JSONObject(goods.size());
//        JSONArray objects=new JSONArray(goods);
//        String str =JSON.toJSONString(goods);
//        resp.getWriter().write("[{\"ClientId\":196401,\"clinetName\":\"teller\"}]");
        JSONArray jsonArray=new JSONArray();
        jsonArray.addAll(goods);
        String str=jsonArray.toJSONString();
        resp.getWriter().write(str);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
